# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
from scipy.stats import t

def perform_regression_test(x):
    '''
    统计检验判断线性回归的斜率是否为 0 
    '''
    time = np.arange(len(x))
    t_mean = np.mean(time)
    x_mean = np.mean(x)
    
    S_tt = sum((time-t_mean)**2)
    S_ty = sum((time-t_mean)*(x-x_mean))
    
    b = S_ty/S_tt
    a = x_mean - t_mean*b
    
    Q = sum((x-(a+b*time))**2)
    
    var_b = Q/((len(x)-2)*S_tt)
    
    if abs(b) <= t.ppf(0.025, len(x)-2) * var_b:
        if Q < 0.05:
            return True
        else:
            return 
    else:
        return False
